/**
 * Copyright (C) 2010 Sergey Grigoriev <s.a.grigoriev@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

build {

  flexSdkHome System.env['flexSdkHome']
  compiler {
    out {
      op '-debug'
    }
    test {
      op '-compiler.library-path+=': "${project.basedir}/lib/flexunit"
      op '-compiler.headless-server'
    }
  }
  testRunner {
    flashPlayer System.env['flashPlayer']
  }

  // Eliminate '-' character from argument and capitalize words
  // Example: for 'simple-swc'  returns 'simpleSwc'
  def folderName =  { name ->
    if (name.contains('-')) {
        int cnt = 0
        name.split('-').collect {
          cnt++ > 0 ? org.apache.commons.lang.StringUtils.capitalize(it) : it
        }.join()
      } else { name }
  }

  // Returns the folder which maps to project's groupId and artifactId. You can write your own mapping function.
  // Example: for project 'net.gmf.examples:simple-swc' returns 'net/gmf/examples/simpleSwc'
  def artifactFolder = { prj, root ->
    def tokens = prj.groupId.tokenize('\\.')
    tokens << prj.artifactId
    def relativePath = tokens.collect {
      folderName(it)
    }.join('/')
    [root, relativePath].join('/')
  }

  // Root folder for sources.
  props['srcRoot'] = { prj -> artifactFolder(prj, project.build.sourceDirectory) }

  // Root folder for tests
  props['testSrcRoot'] = {prj -> artifactFolder(prj, project.build.testSourceDirectory)}
}

